package auth

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePermissionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 更新权限信息
func NewUpdatePermissionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePermissionLogic {
	return &UpdatePermissionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdatePermissionLogic) UpdatePermission(req *types.UpdatePermissionRequest) error {
	_, err := l.svcCtx.AuthRoleRpc.UpdatePermission(l.ctx, &v1.UpdatePermissionRequest{
		Id:             req.Id,
		PermissionPid:  req.PermissionPid,
		PermissionName: req.PermissionName,
		ListOrder:      req.ListOrder,
		Status:         v1.Status(req.Status),
	})

	return err
}
